﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common.Tools;
using Service;
using Spider.Service;
using Timer = System.Windows.Forms.Timer;

namespace WindowsFormsApplication
{
    public partial class EmailCatch1 : Form
    {
        private Timer timer;
        public EmailCatch1()
        {
            InitializeComponent();
            timer = new Timer();
            timer.Interval = 500;
            timer.Tick += new EventHandler(timer1_Tick);
            timer.Start();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            ThreadPool.SetMaxThreads(5, 5);
            SpiderService.SetSpriderCaptainWorkSpeed(5000);
            SpiderService.SetQqSpriderAttribute(txtParam.Text.Trim(), txtCookie.Text.Trim());
            EmailCatchService.StartToCatchEmailAddress("http://g.cnc.qzone.qq.com/cgi-bin/friendshow/cgi_get_visitor_simple?uin=" + txtFirsttask.Text.Trim());
            //MessageBox.Show("已经开始");
        }

        private void Main_Load(object sender, EventArgs e)
        {
            txtCookie.Text =
                @"randomSeed=905220; pgv_pvid=557604552; pgv_info=ssid=s6370905942; rv2=806CB49CCB3952CC50C36AC755AEB011D9F15ABF9435240AC8; property20=949BB223C476685A2F4F051FA754AAF9A26E08C399F8D52AB5F4F226D9624D3A5E0BCE3C652F9AC6; __Q_w_s__QZN_TodoMsgCnt=1; ptui_loginuin=827756467; RK=tG9m7NXRPi; qzone_check=827756467_1419752643; ptisp=cnc; ptcz=813c8faf919ebff6d8ba01bb7c8c401348bded8e265df73cb9e575d4524d9205; pt2gguin=o0827756467; uin=o0827756467; skey=@5LriflY92; p_uin=o0827756467; p_skey=jgRrHWpv5yYeqhRotpcqGUhfEgfDT90c6QqtfuDONcI_; pt4_token=LLLP09GLE1U3WwLVrWJmZg__; qz_gdt=ilej6vataaaf64zbfvaq; appCanvasGoldCouponBubble=true; Loading=Yes; qzspeedup=sdch; qqmusic_uin=; qqmusic_key=; qqmusic_fromtag=; blabla=dynamic; qzmusicplayer=qzone_player_827756467_1419765296784";
            txtFirsttask.Text = "827756467";
            txtParam.Text = "&mask=3&clear=1&rd=0.22741237585432827&g_tk=706892784";
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            lblSpriderRemainTask.Text = SpiderMonitor.GetTodoTaskCount().ToString();
            lblAntRemainTask.Text = SpiderMonitor.RemainAntTask.ToString();
            lblAntFinishedCount.Text = SpiderMonitor.GetVisitedCount().ToString();
            lblSpriderWorking.Text = SpiderMonitor.SpiderIsWorking ? "是" : "否";
            lblAntWorking.Text = SpiderMonitor.AntIsWorking ? "是" : "否";
            btnSpriderStartToWork.Text = SpiderMonitor.SpiderIsWorking ? "停止工作" : "开始工作";
            btnAntStartToWork.Text = SpiderMonitor.AntIsWorking ? "停止工作" : "开始工作";
            lblSpriderCaptainreason.Text = SpiderMonitor.SpiderCaptainStopWorkReason;
            lblAntCaptainReason.Text = SpiderMonitor.AntCaptainStopWorkReason;
            lblAntRemainCount.Text = SpiderMonitor.RemainAntTask.ToString();
            lblAntSuccessFinishedCount.Text = SpiderMonitor.AntSuccessFinishedTaskCount.ToString();
            lblAntFinishedCount.Text = SpiderMonitor.AntFinishedTaskCount.ToString();
            lblSpiderCaptainStartTime.Text = SpiderMonitor.SpiderCaptainStartWorkTime.ToString();
            lblSpiderCaptainEndTime.Text = SpiderMonitor.SpiderCaptainEndWorkTime.ToString();

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void btnQQConfigSet_Click(object sender, EventArgs e)
        {
            SpiderService.SetQqSpriderAttribute(txtParam.Text.Trim(), txtCookie.Text.Trim());
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            ThreadPool.SetMaxThreads((int)nudThreadpool.Value, (int)nudThreadpool.Value);
        }

        private void nupSpriderWorkSpeed_ValueChanged(object sender, EventArgs e)
        {
            SpiderService.SetSpriderCaptainWorkSpeed((int)nupSpriderWorkSpeed.Value*1000);
        }

        private void btnSpriderStartToWork_Click(object sender, EventArgs e)
        {
            if (btnSpriderStartToWork.Text == "开始工作")
                SpiderService.CommandSpiderToWork();
            else
            {
                SpiderService.CommandSpiderStopToWork();
            }

        }

        private void btnAntStartToWork_Click(object sender, EventArgs e)
        {
            if (btnAntStartToWork.Text == "开始工作")
                AntService.CommandAntCaptainToWork();
            else
            {
                AntService.CommandAntCaptainStopToWork();
            }
        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void btnGetSeedQQ_Click(object sender, EventArgs e)
        {
           txtFirsttask.Text= EmailCatchService.GetSeedQQ();
        }
    }
}
